define_extension :revision, :generic do
  require "wondercap/lib/utils/time_converter"
  require "time"

  set(:real_revision) do
    logger.debug "querying revision '#{revision}' from #{scm}"
    real_rev = scm.query_revision(revision) do |cmd|
      logger.debug "executing #{cmd}"
      syscmd_output(cmd)
    end
    if !real_rev
      real_rev = TimeConverter.time_to_int((revision == scm.head) ? Time.now : Time.parse(revision))
    else
      real_rev = Integer(real_rev)
    end

    logger.info "real revision: #{real_rev}"
    real_rev
  end
end
